<?php

$csv = file("umls SN relations.txt");

$triples = array();
$relcount = array();

foreach ($csv as $rel) {
	$rel = rtrim($rel);
	$fields = split("\t", $rel);
	
	if ($fields[1] === 'isa') continue;
	if ($fields[3] !== 'D') continue;
	
	$fields[0] = str_replace(";", "_", $fields[0]); // ; becomes _
	$fields[0] = str_replace(" ", "_", $fields[0]); // SPACE also becomes _
	
	$fields[2] = str_replace(";", "_", $fields[2]); // ; becomes _
	$fields[2] = str_replace(" ", "_", $fields[2]); // SPACE also becomes _
	
	$triples[] = array($fields[0], $fields[1], $fields[2]);
	
	if (!isset($relcount["{$fields[1]}"])) $relcount["{$fields[1]}"] = 1;
	$relcount["{$fields[1]}"]++;
	
}

foreach (array_keys($relcount) as $rel) {
	if ($relcount[$rel] > 1) {
		echo '
<owl:ObjectProperty rdf:ID="' . $rel . '"/>';
	}
}

foreach ($triples as $triple) {
	if ($relcount[$triple[1]] > 1) {
		$property_name = $triple[0] . "_" . $triple[1] . "_" . $triple[2];
		echo '
<owl:ObjectProperty rdf:ID="' . $property_name . '">
	<rdfs:domain rdf:resource="http://localhost/umls-biotop/includes/umls.owl#' . $triple[0] . '"/>
	<rdfs:range rdf:resource="http://localhost/umls-biotop/includes/umls.owl#' . $triple[2] . '"/>
	<rdfs:subPropertyOf rdf:resource="#' . $triple[1] . '"/>
</owl:ObjectProperty>';
	} else {
		echo '
<owl:ObjectProperty rdf:ID="' . $triple[1] . '">
	<rdfs:domain rdf:resource="http://localhost/umls-biotop/includes/umls.owl#' . $triple[0] . '"/>
	<rdfs:range rdf:resource="http://localhost/umls-biotop/includes/umls.owl#' . $triple[2] . '"/>
</owl:ObjectProperty>';
	}
}

	
	
	


?>